#ifndef DEMUXTHREAD_H
#define DEMUXTHREAD_H

#include <string>
#include <QDebug>
#include <thread>

extern "C" {
#include "libavutil/avutil.h"
#include "libavformat/avformat.h"
}

#include "thread.h"
#include "avpacketqueue.h"

class DemuxThread : public Thread
{
public:
    DemuxThread(AVPacketQueue *audio_queue, AVPacketQueue *video_queue);
    ~DemuxThread();

    int Init(const char* url);
    int Start();
    int Stop();

    AVCodecParameters *AudioCodecParameters();
    AVCodecParameters *VideoCodecParameters();

    AVRational AudioStreamTimebase();
    AVRational VideoStreamTimebase();

protected:
    virtual void Run();

private:
    char err2str[256] = {0};
    std::string url_; //文件名
    AVPacketQueue *audio_queue = nullptr;
    AVPacketQueue *video_queue = nullptr;

    AVFormatContext *ifmt_ctx_ = nullptr;

    int audio_index_ = -1;
    int video_index_ = -1;


};

#endif // DEMUXTHREAD_H
